/*   1:    */ package com.htxx.security.cipher;
/*   2:    */ 
/*   3:    */ import java.math.BigInteger;
/*   4:    */ 
/*   5:    */ public class RSACipher
/*   6:    */ {
/*   7:    */   private BigInteger e;
/*   8:    */   private BigInteger d;
/*   9:    */   private BigInteger n;
/*  10: 12 */   private int nRounds = 1;
/*  11:    */   
/*  12:    */   public void setE(BigInteger value)
/*  13:    */   {
/*  14: 19 */     this.e = value;
/*  15:    */   }
/*  16:    */   
/*  17:    */   public void setE(String value)
/*  18:    */   {
/*  19: 23 */     this.e = new BigInteger(value, 16);
/*  20:    */   }
/*  21:    */   
/*  22:    */   public void setD(BigInteger value)
/*  23:    */   {
/*  24: 27 */     this.d = value;
/*  25:    */   }
/*  26:    */   
/*  27:    */   public void setD(String value)
/*  28:    */   {
/*  29: 31 */     this.d = new BigInteger(value, 16);
/*  30:    */   }
/*  31:    */   
/*  32:    */   public void setN(BigInteger value)
/*  33:    */   {
/*  34: 35 */     this.n = value;
/*  35:    */   }
/*  36:    */   
/*  37:    */   public void setN(String value)
/*  38:    */   {
/*  39: 39 */     this.n = new BigInteger(value, 16);
/*  40:    */   }
/*  41:    */   
/*  42:    */   public void setRounds(int value)
/*  43:    */   {
/*  44: 43 */     this.nRounds = value;
/*  45:    */   }
/*  46:    */   
/*  47:    */   public byte[] Encrypt(byte[] message)
/*  48:    */   {
/*  49: 48 */     byte[] former = (byte[])null;
/*  50: 49 */     byte[] complement = (byte[])null;
/*  51: 50 */     byte[] cipher = (byte[])null;
/*  52: 51 */     BigInteger a = null;
/*  53:    */     
/*  54: 53 */     former = new byte[1 + message.length];
/*  55: 54 */     former[0] = 0;
/*  56: 55 */     for (int i = 0; i < message.length; i++) {
/*  57: 56 */       former[(i + 1)] = message[i];
/*  58:    */     }
/*  59: 58 */     a = new BigInteger(former);
/*  60: 59 */     a = a.modPow(this.e, this.n);
/*  61:    */     
/*  62: 61 */     complement = a.toByteArray();
/*  63: 63 */     if (complement[0] != 0) {
/*  64: 64 */       return complement;
/*  65:    */     }
/*  66: 67 */     cipher = new byte[complement.length - 1];
/*  67: 68 */     for (int i = 0; i < cipher.length; i++) {
/*  68: 69 */       cipher[i] = complement[(i + 1)];
/*  69:    */     }
/*  70: 71 */     return cipher;
/*  71:    */   }
/*  72:    */   
/*  73:    */   public byte[] Decrypt(byte[] message)
/*  74:    */   {
/*  75: 77 */     byte[] former = (byte[])null;
/*  76: 78 */     byte[] complement = (byte[])null;
/*  77: 79 */     byte[] cipher = (byte[])null;
/*  78: 80 */     BigInteger a = null;
/*  79:    */     
/*  80: 82 */     former = new byte[1 + message.length];
/*  81: 83 */     former[0] = 0;
/*  82: 84 */     for (int i = 0; i < message.length; i++) {
/*  83: 85 */       former[(i + 1)] = message[i];
/*  84:    */     }
/*  85: 87 */     a = new BigInteger(former);
/*  86: 88 */     a = a.modPow(this.d, this.n);
/*  87:    */     
/*  88: 90 */     complement = a.toByteArray();
/*  89: 92 */     if (complement[0] != 0) {
/*  90: 93 */       return complement;
/*  91:    */     }
/*  92: 96 */     cipher = new byte[complement.length - 1];
/*  93: 97 */     for (int i = 0; i < cipher.length; i++) {
/*  94: 98 */       cipher[i] = complement[(i + 1)];
/*  95:    */     }
/*  96:100 */     return cipher;
/*  97:    */   }
/*  98:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     com.htxx.security.cipher.RSACipher
 * JD-Core Version:    0.7.0.1
 */